package campus.aiit.ssl.controller;

import campus.aiit.ssl.domain.model.DeviceModel;
import campus.aiit.ssl.domain.model.DeviceType;
import campus.aiit.ssl.service.DeviceAttributesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ihaokun
 * @date 2019/12/2 16:36
 */
@Api(description = "设备详情")
@RestController
public class DeviceAttributesController {
  @Resource
  private DeviceAttributesService attributesService;

  @ApiOperation("设备类型（添加）")
  @PostMapping("types")
  public boolean addType(@RequestParam String name){
    return attributesService.addType(name);
  }

  @ApiOperation("设备类型（修改）")
  @PutMapping("types")
  public boolean updateType(@RequestBody DeviceType type){
    return attributesService.modifyType(type);
  }

  @ApiOperation("设备类型（获取）")
  @GetMapping("type")
  public String type(Long id) { return attributesService.getType(id); }

  @ApiOperation("设备类型（列表）")
  @GetMapping("types")
  public DeviceType[] types(){
    return attributesService.types();
  }

  @ApiOperation("设备类型（删除）")
  @DeleteMapping("types")
  public boolean deleteType(long id){
    return attributesService.removeType(id);
  }

  @ApiOperation("设备型号（添加）")
  @PostMapping("models")
  public boolean addModel(@RequestBody DeviceModel model){
    return attributesService.addModel(model);
  }

  @ApiOperation("设备型号（修改）")
  @PutMapping("models")
  public boolean updateModel(@RequestBody DeviceModel model){
    return attributesService.modifyModel(model);
  }

  @ApiOperation("设备型号（列表）")
  @GetMapping("models")
  public DeviceModel[] models(){
    return attributesService.models();
  }

  @ApiOperation("设备品牌（列表）")
  @GetMapping("models/brands")
  public String[] brands(){
    return attributesService.brands();
  }

  @ApiOperation("设备品牌（列表）：根据品牌名")
  @GetMapping("models/{brandName}")
  public DeviceModel[] models(@PathVariable String brandName){
    return attributesService.models(brandName);
  }

  @ApiOperation("设备品牌（删除）")
  @DeleteMapping("models")
  public boolean deleteModel(long id){
    return attributesService.removeModel(id);
  }

  @ApiOperation("设备品牌（查询最大Id）")
  @GetMapping("types/maxId")
  public Long maxId(){return attributesService.getMaxId()+1;}

}